package com.byt.framlib.commonwidget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.byt.framlib.R;

public class CommonTitleBar extends RelativeLayout {

    private RelativeLayout rl_send_comment;
    private TextView tv_send_comment_cancel;
    private TextView tv_send_comment_title;
    private TextView tv_send_comment;
    private Context context;

    public CommonTitleBar(Context context) {
        super(context, null);
        this.context = context;
    }

    public CommonTitleBar(final Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        View.inflate(context, R.layout.bar_common_title, this);
        rl_send_comment = findViewById(R.id.rl_send_comment);
        tv_send_comment_cancel = findViewById(R.id.tv_send_comment_cancel);
        tv_send_comment_title = findViewById(R.id.tv_send_comment_title);
        tv_send_comment = findViewById(R.id.tv_send_comment);
    }

    /**
     * 管理取消按钮
     */
    public void setBackVisibility(boolean visible) {
        if (visible) {
            tv_send_comment_cancel.setVisibility(View.VISIBLE);
        } else {
            tv_send_comment_cancel.setVisibility(View.GONE);
        }
    }

    /**
     * 管理标题
     */
    public void setTitleVisibility(boolean visible) {
        if (visible) {
            tv_send_comment_title.setVisibility(View.VISIBLE);
        } else {
            tv_send_comment_title.setVisibility(View.GONE);
        }
    }

    public void setTitleText(String string) {
        tv_send_comment_title.setText(string);
    }

    public void setTitleColor(int color) {
        tv_send_comment_title.setTextColor(color);
    }

    /**
     * 右标题
     */
    public void setRightTitleVisibility(boolean visible) {
        tv_send_comment.setVisibility(visible ? View.VISIBLE : View.GONE);
    }

    public TextView getRightTextView() {
        return tv_send_comment;
    }

    public void setRightTitle(String text) {
        tv_send_comment.setText(text);
    }

    public void setRightTitleEnabled(boolean enabled) {
        tv_send_comment.setEnabled(enabled);
    }

    /*
     * 点击事件
     */
    public void setOnBackListener(View.OnClickListener listener) {
        tv_send_comment_cancel.setOnClickListener(listener);
    }

    public void setOnRightTextListener(View.OnClickListener listener) {
        tv_send_comment.setOnClickListener(listener);
    }

    /**
     * 标题背景颜色
     *
     * @param color
     */
    public void setBackGroundColor(int color) {
        rl_send_comment.setBackgroundColor(color);
    }

    public Drawable getBackGroundDrawable() {
        return rl_send_comment.getBackground();
    }
}